from django.db import models
from django.contrib.auth.models import User
from django.utils.html import format_html
# Create your models here.

class Activity(models.Model):
    """
    Activity: 活动
    use: 活动报名
    """
    activity_id = models.AutoField(primary_key=True,verbose_name='活动编号')
    # 活动名称
    activity_name = models.CharField(max_length=50,verbose_name='活动名称')
    # 承办人
    undertaker = models.CharField(max_length=15,verbose_name="承办人")
    # 活动起时间
    start_time = models.DateTimeField(blank = True,null=True,verbose_name='活动开始时间')
    # 活动止时间
    end_time = models.DateTimeField(blank=True,null=True,verbose_name="活动结束时间")
    # 活动封面
    activity_cover = models.ImageField(upload_to = 'img',verbose_name="介绍封面")
    # 活动介绍链接
    activity_url = models.URLField(max_length=200,default='#',verbose_name="活动介绍链接")
    # 活动simple介绍
    activity_desc = models.CharField(max_length=100, verbose_name='活动简介')

    # 报名人员
    # 活动-User是多对多的关系
    participants = models.ManyToManyField(User)

    class Meta:
        verbose_name = '活动'
        verbose_name_plural = verbose_name

    def activity_preview(self):
        return format_html('<img src="{}" width="200px" height="300px"/>',self.activity_cover.url)
    activity_preview.short_description = '活动宣传预览'

    def __str__(self) -> str:
        return self.activity_name # 返回活动标题



